from flightanalysis import Section, get_schedule
from flightplotting.plots import plotsec, plotdtw
import plotly
from ipywidgets import interact, interactive, fixed, interact_manual
plotly.offline.init_notebook_mode()
The first task is to read the flight log file to a Section instance. A Section represents the core flight data - position, orientation, velicity etc. The section is generally (but doesnt have to be) standardised to a box coordinate frame, with the origin on the pilot position, Y axis pointing towards centre, Z up, right axis out pilots right shoulder. The takeoff and landing are chopped off so only the scored flight remains.
flown = Section.from_csv("examples/P23.csv").subset(102, 475)
plotsec(flown, color="green")
The sequence flown is read into a Schedule instance. This contains a list of manoeuvres, with each manoeuvre containing a list of elements (Line, Loop, Snap, Spin, StallTurn). Each eleemnt also contains some basic scaling information, length for lines, radius for loops etc. The Schedule class contains methods return scaled copies of itself. The recorded flight was flown roughly at 170m depth, so the scale_distance method works here. It also contains methods to create a Section instance with template data. This section object is special because all the manoeuvres and elements are labelled.
p23 = get_schedule("F3A", "P23")
template = p23.scale_distance(170).create_raw_template("left", 25.0, 170.0)
plotsec(template)
We want to transfer these labels from the template to the flown data. The align method on the section class performs dynamic time warping based on the axis rate (roll, pitch and yaw). Dynamic time warping gives a measure of the distance between two time series that may differ in the time axis. It also gives a path, to map the indeces from one to the other. As long as the template has been roughly scaled to the flight, and the flight was flown reasonably well this should work.
dist, aligned = Section.align(flown, template, 2)
plotdtw(p23.manoeuvres[0].get_data(aligned), p23.manoeuvres[0].elements).show()
Now the match_intention method goes through all the elements of the aligned data and adjusts the element scaling to sut. The correct_intention method then adjusts the scaled elements to reflect the judging criteria (not yet all of it).
corrected_p23 = p23.match_intention(aligned).correct_intention()
corrected_template = corrected_p23.create_matched_template(aligned)
fig = plotsec(p23.manoeuvres[0].get_data(aligned))
fig.add_traces(plotsec(p23.manoeuvres[0].get_data(corrected_template), color="blue").data).show()